package cn.terminus.data.customer.customdemand.impl;

import cn.terminus.common.customer.bean.customdemand.dto.*;
import cn.terminus.data.customer.customdemand.dao.CustomDemandDao;
import cn.terminus.data.customer.customdemand.mapper.CustomDemandMapper;
import cn.terminus.result.common.page.TerminusPageAble;
import cn.terminus.result.common.page.TerminusPageInfo;
import cn.terminus.result.common.util.BeanCopyUtils;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * (CustomDemand)表服务实现类
 *
 * @author makejava
 * @since 2021-07-08 11:18:44
 */
@Repository
public class CustomDemandDaoImpl implements CustomDemandDao {
    @Resource
    private CustomDemandMapper customDemandMapper;

    @Override
    public Integer add(CustomDemandNewDto dto) {
        return customDemandMapper.add(dto);
    }

    @Override
    public Integer update(CustomDemandNewDto dto) {
        return customDemandMapper.update(dto);
    }

    @Override
    public List<CustomDemandResultDto> gets(CustomDemandGetsDto dto) {
        return customDemandMapper.gets(dto);
    }

    @Override
    public List<CustomDemandResultDto> query(CustomDemandQueryDto dto) {
        return customDemandMapper.query(dto);
    }

    @Override
    public Integer delete(CustomDemandDeleteDto dto) {
        return customDemandMapper.delete(dto);
    }

    @Override
    public TerminusPageAble<CustomDemandResultDto> page(CustomDemandQueryDto dto, TerminusPageInfo page) {
        PageHelper.startPage(page.getCurrentPage(), page.getPageSize());
        Page<CustomDemandResultDto> result = (Page<CustomDemandResultDto>) customDemandMapper.query(dto);
        return new TerminusPageAble<>(BeanCopyUtils.copy(result.getResult(), CustomDemandResultDto.class), page, result.getTotal());
    }
}
